Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/helper-hoist-variables

Package Overview
Dependencies
Maintainers
4
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-hoist-variables

Helper function to hoist variables

  • 8.0.0-alpha.11
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26M
increased by2.69%
Maintainers
4
Weekly downloads
 
Created

What is @babel/helper-hoist-variables?

The @babel/helper-hoist-variables package is a utility that is used within the Babel compiler to hoist variable declarations to the top of their respective scopes during the code transformation process. This is part of the Babel's internal mechanism to ensure that the transformed code adheres to the scoping rules of ECMAScript and to avoid issues with variable declarations in the transpiled output.

What are @babel/helper-hoist-variables's main functionalities?

Variable Hoisting

This feature allows the package to traverse a given AST (Abstract Syntax Tree) path and find all variable declarations. It then hoists these declarations to the top of the function or program scope. The 'emitOnScope' parameter is a callback that is called with an identifier for each variable that needs to be hoisted.

function hoistVariables(path, emitOnScope) {
  const names = Object.create(null);
  path.traverse({
    VariableDeclarator({ node }) {
      if (node.id.type === 'Identifier') {
        names[node.id.name] = true;
      }
    }
  });
  Object.keys(names).forEach(name => {
    emitOnScope.push({ id: t.identifier(name) });
  });
}

Other packages similar to @babel/helper-hoist-variables

FAQs

Package last updated on 07 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc